﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Drawing;
using System.Drawing.Text;

namespace Freshome.p.Controllers
{
    public class FoodController : Controller
    {
        public ViewResult Index(b.MajorawCateg ct = b.MajorawCateg.None, short id = default(short))
        {
            MajorawBoy mb = new MajorawBoy();
            var mjs = new Models.Majoraws()
            {
                Entities = mb.PrimeMajoraws(ct),
                Majoraw_ct = ct,
                Majoraw_id = id
            };
            if (id > default(short))
            {
                var mj = mb.GetEntity(m => m.Mid == id);
                if (mj != null)
                {
                    mjs.Majoraw_nm = mj.Name;
                    mjs.Majoraw_nt = mj.Notes;
                }
            }
            ViewBag.Category = string.IsNullOrEmpty(mjs.Majoraw_nm) ? b.Liboat.MajorawCategory(ct) : mjs.Majoraw_nm;
            return View(mjs);
        }
        [OutputCache(Duration = 1)]
        public ViewResult Majorized(b.MajorawCateg ct, string nm, short id, string nt)
        {
            RecipeBoy boy = new RecipeBoy();
            var mrs = new Models.Recipes
            {
                Mid = id, Name = nm, Notes = nt,
                Entities = boy.PrimeRecipes(ct, id)   // 如果id = default(short)，则提取全部指定类别的食谱
            };
            ViewBag.Category = string.IsNullOrEmpty(nm) ? b.Liboat.MajorawCategory(ct) : nm;
            return View(mrs);
        }
    }
}
